package com.gaoyang.util.net;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;

public class HttpResult {

    private static Logger logger = LoggerFactory.getLogger(HttpResult.class);

    public static final int STATUS_EXP = 9999;

    private int status;
    private long cost;
    private InputStream inputStream;
    private String result;
    private Exception exception;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public long getCost() {
        return cost;
    }

    public void setCost(long cost) {
        this.cost = cost;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public Exception getException() {
        return exception;
    }

    public void setException(Exception exception) {
        this.exception = exception;
    }

    public String getResult() {
        if (result == null && inputStream != null) {
            result = IOUtils.toString(inputStream);
        }
        return result;
    }

    public void setResult(String result){
        this.result=result;
    }

    public String getResult(String charset) {
        if (result == null && inputStream != null) {
            result = IOUtils.toString(inputStream, charset);
        }
        return result;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
